package com.ruoyi.eqmonitor.dispose.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.eqmonitor.dispose.domain.ExteriorSiteAlarm;
import com.ruoyi.eqmonitor.dispose.service.IExteriorSiteAlarmService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 微站报警
 * @author ruoyi
 * @date 2023-04-11
 */
@RestController
@RequestMapping("/exterior/alarm")
public class ExteriorSiteAlarmController extends BaseController{
    
    @Autowired
    private IExteriorSiteAlarmService exteriorSiteAlarmService;

    /**
     * 微站报警列表
     */
    @ApiOperation("微站报警列表")
    @GetMapping("/list")
    public TableDataInfo<?> list(ExteriorSiteAlarm exteriorSiteAlarm){
        startPage();
        List<ExteriorSiteAlarm> list = exteriorSiteAlarmService.selectExteriorSiteAlarmList(exteriorSiteAlarm);
        return getDataTable(list);
    }

    /**
     * 微站报警详情
     */
    @ApiOperation("微站报警详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return AjaxResult.success(exteriorSiteAlarmService.selectExteriorSiteAlarmById(id));
    }

    /**
     * 新增微站报警
     */
    @ApiOperation("新增微站报警")
    @Log(title = "微站报警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExteriorSiteAlarm exteriorSiteAlarm){
        return toAjax(exteriorSiteAlarmService.save(exteriorSiteAlarm));
    }

    /**
     * 修改微站报警
     */
    @ApiOperation("修改微站报警")
    @PutMapping
    public AjaxResult edit(@RequestBody ExteriorSiteAlarm exteriorSiteAlarm){
        return toAjax(exteriorSiteAlarmService.updateById(exteriorSiteAlarm));
    }

    /**
     * 删除微站报警
     */
    @ApiOperation("删除微站报警")
    @Log(title = "微站报警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(exteriorSiteAlarmService.removeByIds(Arrays.asList(ids)));
    }
    
    /**
     * 导出微站报警列表
     */
    @ApiOperation("导出微站报警列表")
    @Log(title = "微站报警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExteriorSiteAlarm exteriorSiteAlarm){
        List<ExteriorSiteAlarm> list = exteriorSiteAlarmService.selectExteriorSiteAlarmList(exteriorSiteAlarm);
        ExcelUtil<ExteriorSiteAlarm> util = new ExcelUtil<ExteriorSiteAlarm>(ExteriorSiteAlarm.class);
        util.exportExcel(response, list, "微站报警数据");
    }
    
}
